package o;

import android.app.job.JobInfo;
import android.app.job.JobInfo.Builder;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build.VERSION;
import com.huawei.appmarket.service.predownload.jobservice.UrgentUpdateJobService;
import com.huawei.appmarket.service.predownload.jobservice.WlanPeriodicJobService;
import com.huawei.appmarket.service.predownload.jobservice.WlanUpdateJobService;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.util.HashMap;
import java.util.Map;

public class edq {
    private static Map<Integer, Class<? extends JobService>> ˋ = new HashMap();
    private static edq ˏ;
    private JobScheduler ˊ = ((JobScheduler) ContentManager.getInstant().getContext().getSystemService("jobscheduler"));

    static {
        ˋ(HwAccountConstants.MY_PERMISSIONS_REQUEST_READ_PHONE_STATE, UrgentUpdateJobService.class);
        ˋ(10002, WlanUpdateJobService.class);
        ˋ(10001, WlanPeriodicJobService.class);
    }

    private static void ˋ(int i, Class<? extends JobService> cls) {
        ˋ.put(Integer.valueOf(i), cls);
    }

    private static Class<? extends JobService> ॱ(int i) {
        return (Class) ˋ.get(Integer.valueOf(i));
    }

    public static edq ॱ() {
        if (ˏ == null) {
            ˏ = new edq();
        }
        return ˏ;
    }

    private edq() {
    }

    public boolean ˎ(int i, boolean z, boolean z2, long j, long j2) {
        long j3 = j + j2;
        JobInfo ˊ = ˊ(i);
        if (ˊ != null) {
            long intervalMillis = ˊ.getIntervalMillis();
            Logger.ˏ("JobSchedulerManager", "job: " + i + " old periodic: " + intervalMillis + ", new periodic: " + j3);
            if (j3 < 900000 || j3 == intervalMillis) {
                Logger.ˎ("JobSchedulerManager", "job: " + i + " has been scheduled, cannot schedule again");
                return false;
            }
            Logger.ˎ("JobSchedulerManager", "job: " + i + " has been scheduled, but periodic interval is changed");
            ˏ(i);
        }
        Context ˋ = ContentManager.getInstant().getContext();
        Class ॱ = ॱ(i);
        if (ॱ == null) {
            Logger.ˎ("JobSchedulerManager", "cannot schedule the jobService, no jobService for the id: " + i);
            return false;
        }
        Builder builder = new Builder(i, new ComponentName(ˋ, ॱ));
        builder.setRequiresCharging(z);
        if (z2) {
            builder.setRequiredNetworkType(2);
        } else {
            builder.setRequiredNetworkType(1);
        }
        if (j3 >= 900000) {
            builder.setPeriodic(j3);
        }
        if (1 == this.ˊ.schedule(builder.build())) {
            return true;
        }
        return false;
    }

    private void ˏ(int i) {
        if (this.ˊ == null) {
            Logger.ˏ("JobSchedulerManager", "sheduler is null");
        } else {
            this.ˊ.cancel(i);
        }
    }

    private JobInfo ˊ(int i) {
        if (VERSION.SDK_INT >= 24) {
            return this.ˊ.getPendingJob(i);
        }
        for (JobInfo jobInfo : this.ˊ.getAllPendingJobs()) {
            if (jobInfo.getId() == i) {
                return jobInfo;
            }
        }
        return null;
    }
}
